package com.techshine.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.techshine.entity.Constant;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.techshine.common.base.BaseController;
import com.techshine.entity.Msg;
import com.techshine.service.MsgService;
import com.techshine.util.StringUtil;
/** 
 * 说明：留言
 * 创建时间：2024-04-18
 */
@Controller
@RequestMapping(value="/msg")
public class MsgController extends BaseController {
	
	
	@Resource
	private MsgService msgService;
	
	
	@ResponseBody 
    @RequestMapping("/queryByKey")
    public Map<String, Object>  queryByKey(String id) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(id)){
			Msg entity = msgService.queryByKey(id);
			map.put("result", entity);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
    }
   
    @ResponseBody 
    @RequestMapping("/queryListByPage")
    public Map<String, Object> queryListByPage(Msg entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		List<Msg> list = msgService.queryListByPage(entity);
		map.put("code", 0); 
		map.put("data", list);
		map.put("count", entity.getCount());
		return map;
    }
    @ResponseBody 
    @RequestMapping("/queryList")
    public Map<String, Object> queryList(Msg entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		
		List<Msg> list = msgService.queryList(entity);
		map.put("status", 200);
		map.put("result", list);
		
		return map;
    }
    @ResponseBody 
    @RequestMapping("/insert")
    public Map<String, Object> insert(Msg entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		//entity.setCreateTime(DateUtil.getCurrentDate());
		//entity.setUpdateTime(DateUtil.getCurrentDate());
    	String name = entity.getName();
    	if(name==null||name.length()>50) {
    		map.put("status", 200);
    		map.put("msg", "名字必填且1-50个字!");
    	}
    	
    	String comm = entity.getComm();
    	if(comm!=null&&comm.length()>100) {
    		map.put("status", 200);
    		map.put("msg", "单位名称不能超过100字!");
    		return map;
    	}
    	String phone = entity.getPhone();
    	if(phone!=null&&phone.length()>15) {
    		map.put("status", 200);
    		map.put("msg", "电话不能超过15字!");
    		return map;
    	}
    	String Email = entity.getEmail();
    	if(Email!=null&&Email.length()>50) {
    		map.put("status", 200);
    		map.put("msg", "邮箱名称不能超过100字!");
    		return map;
    	}
    	
    	String Cont = entity.getCont();
    	if(Cont==null||Cont.length()>50) {
    		map.put("status", 200);
    		map.put("msg", "内容必填且1-300个字!");
    	}
    	
    	
    	
    	if(entity.getId()!=null&&entity.getId()>0) {
    		msgService.updateByKeySelective(entity);
    	}else {
    		msgService.insertSelective(entity);
    	}
		map.put("status", 200);
		map.put("msg", "成功!");
		
		return map;
    }
    @ResponseBody 
    @RequestMapping("/update")
    public Map<String, Object> update(Msg entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
		
		//entity.setUpdateTime(DateUtil.getCurrentDate());
		if(StringUtil.isNotEmpty(entity.getId())){
			msgService.updateByKeySelective(entity);
			map.put("result", entity);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
    }
    @ResponseBody 
    @RequestMapping("/delete")
    public Map<String, Object> delete(Msg entity) throws Exception {
    	Map<String, Object> map = new HashMap<String, Object>();
    	
		if(StringUtil.isNotEmpty(entity.getId())){
			msgService.delete(entity);
			map.put("result", entity);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
    }
  
	
	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public Map<String, Object> deleteAll() throws Exception{
		
		return null;
	}
	@RequestMapping(value="/delmore")
	@ResponseBody
	public Map<String, Object> delmore(String ids) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		if(StringUtil.isNotEmpty(ids)){
			msgService.delmore(ids);
			map.put("status", 200);
    	}else{
    		map.put("msg", "参数错误");
			map.put("status", 902);
    	}
		return map;
	}

	@RequestMapping(value = "/finddoot")
	@ResponseBody
	public Map<String,Object> finddoot(Constant constant) throws Exception {
		Map<String,Object> map=new HashMap<>();
		if(StringUtil.isNotEmpty(constant.getId())){
			Constant aaa =msgService.finddoot(constant);
			String qq=aaa.getVal();
			map.put("val",qq);
			map.put("status",200);
		}else{
			map.put("msg", "参数错误");
			map.put("status", 902);
		}
		return map;
	}
}
